// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next';
import { BeError, BeSuccess, ResponseDataType } from '@/utils/response';
import { syncProjects } from '@/services/gitlab';

export default async function handler(req: NextApiRequest, res: NextApiResponse<ResponseDataType>) {
  if (req.method?.toLowerCase() !== 'get') {
    res.status(200).json(BeError('不支持请求类型'));
    res.end();
    return;
  }
  try {
    const ret = await syncProjects();
    res.status(200).json(BeSuccess(ret));
  } catch (error: any) {
    res.status(500).json(BeError(error));
  }
}
